// pages/distribut/logistics/logistics.js
var app = getApp();
var request = app.request;
var setting = app.globalData.setting;
var common = require('../../../utils/common.js');
var util = require('../../../utils/util.js');
import LoadMore from '../../../utils/LoadMore.js'
var load = new LoadMore;
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		time: app.getym(),
		currentdate: {
			hao: new Date().getDate(),
			zj: new Date().getDay(),
			nianyuer: new Date().getFullYear() + '年' + ((new Date().getMonth() + 1) > 10 ? new Date()
				.getMonth() + 1 : '0' + (new Date().getMonth() + 1)) + '月' + (new Date().getDate() >= 10 ?
					new Date().getDate() : '0' + new Date().getDate()) + '日',
		},
		currentlist: app.getDate(new Date()),
		zlist: ['周日', '周一', '周二', '周三', '周四', '周五', '周六',],
		currentTab: 1,
		page: 3,
		one: 0,
		two: 0,
		three: 0,
		currentPage: 1,
		list: []
	},
	itemclick(e) {
		this.setData({
			time: app.globalData.parseTime(e.detail, '{y}年{m}月'),
			currentlist: app.getDate(e.detail),
			currentdate: {
				hao: new Date(e.detail).getDate(),
				zj: new Date(e.detail).getDay(),
				nianyuer: app.globalData.parseTime(e.detail, '{y}年{m}月{d}日')
			}
		})
	},
	itemclick1(e) {
		this.setData({
			currentdate: e.detail
		})
	},
	clickMenu(e) {
		// var that = this;
		// if (that.data.click) return false;
		// that.data.click = true;
		//在个人中心浏览其他入口页面前判断是否登录
		// if (!that.data.userInfo.user_id) {
		//   app.getUserInfo(function (userInfo) {
		//     that.setData({ userInfo: userInfo, click: false });
		//   }, true, false);
		//   return false;
		// }

		wx.navigateTo({
			url: e.currentTarget.dataset.url
		});
	},


	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		if (options.scene) {
			var scene = decodeURIComponent(options.scene)
			var data = scene.split('&')
			options.date = data[0].split('=')[1]
			options.first_leader = data[1].split('=')[1]
		}
		// if (options.first_leader) {
		//     wx.setStorageSync('first_leader', options.first_leader);
		// }  
		this.getDate(options.date);
	},
	tz(e) {
		let info = e.currentTarget.dataset.id
		wx.navigateTo({
			url: e.currentTarget.dataset.url + '?id=' + info.id
		});
	},
	// 确认收货
	confirm(e) {
		let that = this
		let data = {
			id: e.currentTarget.dataset.id.id,
			confirm_count: e.currentTarget.dataset.id.goods_count
		}
		wx.showModal({
			title: '提示',
			content: '是否确认收货？',
			success(res) {
				if (res.confirm) {
					request.post('/api/shop/confirmDelivery', {
						data: data,
						success: function (res) {
							if (res.data.status == 1) {
								wx.showToast({
									title: '收货成功',
									icon: 'none',
									duration: 1500,
								})
								that.getDate()
							}
						}
					})
				} else if (res.cancel) {
					console.log('用户点击取消')
				}
			}
		})
	},
	getDate: function (date) {
		var that = this;
		request.get('/api/shop/getDeliveryList', {
			data: {},
			success: function (res) {
				if (res.data.status == 1) {
					let list = [...res.data.result.data]
					// list.forEach(e => {
					// 	e.start_time = util.formatTime(e.start_time, 'Y/M/D h:m:s');
					// 	e.delivery_time = util.formatTime(e.delivery_time,
					// 		'Y/M/D h:m:s');
					// })
					that.setData({
						list: list
					})
				}

			}
		})
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})